

#property copyright "Copyright"
#property link "mingxinhe@gmail.com"

extern string comment="EA";              // comment to display in the order
extern int magic=1234;                   // magic number required if you use different settings on a same pair, same timeframe

extern string moneymanagement="Money Management";

extern double lots=0.1;                  // lots size
extern bool mm=false;                    // enable risk management
extern double risk=1;                    // risk in percentage of the account
extern double minlot=0.01;               // minimum lots size
extern double maxlot=100;                // maximum lots size
extern double lotdigits=2;               // lot digits, 1 for mini, 2 for micro
extern bool martingale=false;          // enable the martingale
extern double multiplier=2.0;          // multiplier used for the martingale
//extern bool basketpercent=false;       // enable the basket percent
//extern double profit=10;               // close all orders if a profit of 10 percents has been reached
//extern double loss=30;                 // close all orders if a loss of 30 percents has been reached
extern bool basket_amount = false;       // enable the basket amount
extern double profit=20;                 // close all orders if a profit of 20 has been reached
extern double loss=10000;                  // close all orders if a loss of 500 has been reached
extern bool lot_increase = false;        // enable the lot increase
extern double lot_inc_size = 0.1;        // size of the lot increase

extern bool lot_decrease = true;        // enable the lot decrease
extern double lot_dec_size = 0.01;        // size of the lot decrease



extern bool log_file = false;  

extern string ordersmanagement="Order Management";

extern bool ecn=false;                   // make the expert compatible with ecn brokers
extern bool oppositeclose=false;          // close the orders on an opposite signal
extern bool reversesignals=false;        // reverse the signals, long if short, short if long
extern int maxtrades=1;                // maximum trades allowed by the traders
extern int tradesperbar=1;               // maximum trades per bar allowed by the expert
extern bool hidesl=false;                // hide stop loss
extern bool hidetp=false;                // hide take profit
extern double stoploss=0;                // stop loss
extern double takeprofit=0;              // take profit
extern double trailingstart=0;           // profit in pips required to enable the trailing stop
extern double trailingstop=0;            // trailing stop
extern double trailingprofit=0;          // trailing profit
extern double trailingstep=1;            // margin allowed to the market to enable the trailing stop
extern double breakevengain=0;           // gain in pips required to enable the break even
extern double breakeven=0;               // break even
int expiration=0;                        // expiration in minutes for pending orders
extern int slippage=0;                          // maximum difference in pips between signal and order
extern double maxspread=100;             // maximum spread allowed by the expert

string goldminer="Gold Miner Settings";

bool goldminerentry=false;
int grisk=3;
int countbars=300;
int goldminershift=1;             // bar in the past to take in consideration for the signal

string nonlagma="NonLagMA Settings";

bool nonlagmafilter=false;
int price=0;
int length=12;
int displace=0;
int filter2=0;
int clr=1;
int colorbarback=-3;
double deviation=0;
bool nonlagmaexit=false;
int price2=0;
int length2=12;
int displace2=0;
int filter22=0;
int clr2=1;
int colorbarback2=-3;
double deviation2=0;
int nonlagmashift=1;

extern string slopeline="Slope Direction Line Settings";

extern bool slopelinefilter=false;
extern int sdltimeframe=0;
extern int period=80;
extern int method=3;
extern int sdlprice=0;
extern int sdlshift=1;


extern string slopeline1="Slope Direction Line Filter 1 Settings";

extern bool slopelinefilter_1=false;
extern int sdltimeframe_1=0;
extern int period_1=80;
extern int method_1=3;
extern int sdlprice_1=0;
extern int sdlshift_1=1;

string damiani="Damiani Settings";

bool damianifilter=false;         // damiani filter
int damianitimeframe=0;           // damiani timeframe
int Viscosity=7;
int Sedimentation=50;
double Threshold_level=1.1;
bool lag_supressor=false;
int damianishift=1;               // damiani shift

extern string timefilter="Time Filter";

extern int gmtshift=1;                   // gmt offset of the broker
extern bool generalfilter=false;         // enable time filter
extern int starthour=7;                  // start hour to trade after this hour
extern int startminutes=0;               // minutes of the start hour
extern int endhour=21;                   // stop to trade after this hour
extern int endminutes=0;                 // minutes of the start hour

extern string timefilter2="Time Filter 2";
extern bool generalfilter2=false;         // enable time filter
extern int starthour2=9;                  // start hour to trade after this hour
extern int startminutes2=0;               // minutes of the start hour
extern int endhour2=21;                   // stop to trade after this hour
extern int endminutes2=0;                 // minutes of the start hour

extern string timefilter3="Time Filter 3";
extern bool generalfilter3=false;         // enable time filter
extern int starthour3=7;                  // start hour to trade after this hour
extern int startminutes3=0;               // minutes of the start hour
extern int endhour3=21;                   // stop to trade after this hour
extern int endminutes3=0;                 // minutes of the start hour

extern bool tradesunday=true;            // trade on sunday
extern bool fridayfilter=false;          // enable special time filter on friday
extern int fridayhour=21;                // stop to trade after this hour
extern int fridayminutes=0;              // minutes of the friday hour

extern string qqeentry = "=== QQE Entry ===";
extern bool     bQQEEntry            = false;
extern int      iQQEEntryTimeframe   = 0; 
extern int      iQQEEntry_SF         = 12;
extern int      iQQEEntry_RSI_Period = 14;
extern int      iQQEEntryShift       = 1;
       datetime dtQQEEntryCross      = D'1970.01.01';
       
string nonLagDotEntry = "=== NonLagDot Entry ===";

bool       bNonLagDotEntry      = false;
bool       bNonLagDotEnterAlways= false;
int        iNLDEntryTimeFrame   = 0; // Applied timeframe. if 0 -- current
int        iNLDEntryPrice       = 0; // Applied price 0..6
int        iNLDEntryLength      = 20; 
int        iNLDEntryFilter      = 0; // >= 0
int        iNLDEntryShift       = 1; // >= 0

string     ArrowRSI          =  "=== ARROR_RSI-8_CROSS Entry ===";
bool       UseArrowRsiEntry  =  false; //if true the ea will use arrow_rsi entries;   
int        TF                = 0 ;    //timeframe for indicator;
int        RSIPeriod         = 14 ;   //period for RSI;

extern string SlopeDirectionEntry = "=== Slope Direction Line Entry ===";
extern bool       bSlopeDirectionEntry=true;     //if true uses Slope Direction Line for Entry
extern bool       bSlopeDirectionEntryAlways=true;     //if true ea will not wate color change

extern int        iSlopeDirectionEntry_TimeFrame      = 0; // Applied timeframe. if 0 -- current
extern int        iSlopeDirectionEntryPeriod=80;     //Slope Direction Line Period
extern int        iSlopeDirectionEntryMethod=3;      //Slope Direction Line method 0..3
extern int        iSlopeDirectionEntryPrice=0;       //Slope Direction line price: 0..6  0-PRICE_CLOSE 
extern int        iSlopeDirectionEntryShift=1;       //Slope Direction line shift;



extern string wprfilterstr = "=== WPR Direction Filter ===";
extern bool       WPR_Direction_Filter = true;
extern int        WPR_TimeFrame = 0;
extern int        WPR_Top_Level = -20;
extern int        WPR_Bottom_level = -80; 
extern int        WPR_Period = 14;
extern int        WPR_Shift  = 1;

extern string wprfilterstr_1 = "=== WPR Direction Filter 1 ===";
extern bool       WPR_Direction_Filter_1 = true;
extern int        WPR_TimeFrame_1 = 0;
extern int        WPR_Top_Level_1 = -20;
extern int        WPR_Bottom_level_1 = -80; 
extern int        WPR_Period_1 = 14;
extern int        WPR_Shift_1  = 1;


extern string qqefilter = "=== QQE Filter ===";
extern bool     bQQEFilter            = false;
extern int      iQQEFilterTimeframe   = 0; 
extern int      iQQEFilter_SF         = 12;
extern int      iQQEFilter_RSI_Period = 14;
extern int      iQQEFilterShift       = 1;


extern string qqefilter_1 = "=== QQE Filter 1 ===";
extern bool       QqeFilter_1          = true;
extern int        QqeTimeframe_1       = 0;
extern int        QqeSf_1              = 12;
extern int        QqeRsiPeriod_1       = 14;
extern int        QqeShift_1           =  1;  


extern string qqefilter_2 = "=== QQE Filter 2 ===";
extern bool       QqeFilter_2          = false;
extern int        QqeTimeframe_2       = 0;
extern int        QqeSf_2              = 12;
extern int        QqeRsiPeriod_2       = 14;
extern int        QqeShift_2           =  1;



string nonLagDotFilter1 = "=== NonLagDot Filter 1 ===";

bool       bnonLagDotFilter1 = false;
int        iNLDTimeFrame1    = 0; // Applied timeframe. if 0 -- current
int        iNLDPrice1        = 0; // Applied price 0..6
int        iNLDLength1       = 20; 
int        iNLDFilter1       = 0; // >= 0
int        iNLDShift1        = 1; // >= 0

string nonLagDotFilter2 = "=== NonLagDot Filter 2 ===";

bool       bnonLagDotFilter2 = false;
int        iNLDTimeFrame2    = 0; // Applied timeframe. if 0 -- current
int        iNLDPrice2        = 0; // Applied price 0..6
int        iNLDLength2       = 20; 
int        iNLDFilter2       = 0; // >= 0
int        iNLDShift2        = 1; // >= 0

string SuperTrendFilter = "=== Super Trend Filter ===";

bool       bSuperTrendFilter = false;
int        iSTTimeFrame      = 0; // Applied timeframe. if 0 -- current
int        iSTShift          = 1; // >= 0


extern string     qqeexit = "=== QQE Exit ==="; 
extern bool       QqeExit                 =  true;
extern int        QqeExitTimeframe        =  0;
extern int        QqeExitSf               =  12;
extern int        QqeExitRsiPeriod        =  14;
extern int        QqeExitShift            =  1;  






string nonLagDotExit = "=== SDL_MAM Exit ===";

bool       bSdlMamExit       = false;
int        iSdlPeriod        =20;        //SDL_MAM period;
int        iSdlMethod        =3;         //SDL_MAM method 0..3
int        iSdlPrice         =0;         //SDL_MAM applied price 0..6

string  NLD_Exit =  "=== NonLagDot Exit ===";
bool       bNonLagDotExit    =  false;    //if true the ea uses nonlagdot exit;
int        NLDExitTF         =  0;       //nonlagdot timeframe (in minutes): 0 - current tf;
int        Price             =  0;       
int        Length            =  20;
int        Displace          =  0;
int        Filter            =  0;
int        Color             =  1;
int        ColorBarBack      =  0;
double     Deviation         =  0;         

extern string SlopeDirectionLine = "=== Slope Direction Line Exit ===";
extern bool       bSlopeDirectionExit=true;     //if true uses Slope Direction Line for exit
extern int        iSlopeDirection_TimeFrame      = 0; // Applied timeframe. if 0 -- current
extern int        iSlopeDirectionPeriod=80;     //Slope Direction Line Period
extern int        iSlopeDirectionMethod=3;      //Slope Direction Line method 0..3
extern int        iSlopeDirectionPrice=0;       //Slope Direction line price: 0..6  0-PRICE_CLOSE 
extern int        iSlopeDirectionExitShift=1;       //Slope Direction line shift


extern string XO_A_H_Exit        = "=== XO_A_H Exit ===";
extern bool       bUseXO_A_H_Exit        =   false; //if true the ea will use XO_A_H exit;
extern int        iXO_A_H_TimeFrameExit  = 0; // Applied timeframe. if 0 -- current
extern int        iXO_A_H_BoxSizeExit    = 15;
extern int        iXO_A_H_UpLevelExit    = 2;
extern int        iXO_A_H_DnLevelExit    = -2;

/*
extern int        iNLDExitTimeFrame    = 0; // Applied timeframe. if 0 -- current
extern int        iNLDExitPrice        = 0; // Applied price 0..6
extern int        iNLDExitLength       = 20; 
extern int        iNLDExitFilter       = 0; // >= 0
extern int        iNLDExitShift        = 1; // >= 0
*/
extern string XO_A_H_Filter = "=== XO_A_H Filter ===";

extern bool       bXO_A_H_Filter = false;
extern int        iXO_A_H_TimeFrame      = 0; // Applied timeframe. if 0 -- current
extern int        iXO_A_H_BoxSize        = 15;
extern int        iXO_A_H_UpLevel        = 2;
extern int        iXO_A_H_DnLevel        = -2;
extern int        iXO_A_H_Shift          = 1;

extern string XO_A_H2_Filter = "=== XO_A_H2 Filter ===";

extern bool       bXO_A_H2_Filter        = false;
extern int        iXO_A_H2_TimeFrame     = 0; // Applied timeframe. if 0 -- current
extern int        iXO_A_H2_BoxSize       = 15;
extern int        iXO_A_H2_UpLevel       = 2;
extern int        iXO_A_H2_DnLevel       = -2;
extern int        iXO_A_H2_Shift         = 1;

extern string XO_A_H3_Filter = "=== XO_A_H3 Filter ===";

extern bool       bXO_A_H3_Filter        = false;
extern int        iXO_A_H3_TimeFrame     = 0; // Applied timeframe. if 0 -- current
extern int        iXO_A_H3_BoxSize       = 15;
extern int        iXO_A_H3_UpLevel       = 2;
extern int        iXO_A_H3_DnLevel       = -2;
extern int        iXO_A_H3_Shift         = 1;

extern string XO_A_H4_Filter = "=== XO_A_H4 Filter ===";

extern bool       bXO_A_H4_Filter        = false;
extern int        iXO_A_H4_TimeFrame     = 0; // Applied timeframe. if 0 -- current
extern int        iXO_A_H4_BoxSize       = 15;
extern int        iXO_A_H4_UpLevel       = 2;
extern int        iXO_A_H4_DnLevel       = -2;
extern int        iXO_A_H4_Shift         = 1;

string  ALF_UltimateFilter="=== ALF_Ultimate Filter ===";
bool       bALF_Ultimate     =   false;   //if true the ea uses ALF_Ultimate as filter
int        ALF_UltimateTF    =  0;       //timeframe for ALF_Ultimate in minutes: 0 - current;                
int        KPeriod           =  20,
                  DPeriod           =  2,
                  SPeriod           =  2, 
                  MAMode            =  0,
                  MAPrice           =  0;
int              BuyAlertLevel=1,SellAlertLevel=-1;

extern string  AwesomeFilter="=== Awesome Filter ===";
extern bool       bUseAwesome       =  false;    //if true the ea uses Awesome;
extern int        AwesomeTF         =  0;       //Awesome timeframe in minutes: 0 - current tf;
extern int        AwesomeShift      =  1; 


extern string  AwesomeFilter1="=== Awesome 1 Filter ===";
extern bool       bUseAwesome_1       =  false;    //if true the ea uses Awesome;
extern int        AwesomeTF_1         =  0;       //Awesome timeframe in minutes: 0 - current tf;
extern int        AwesomeShift_1      =  1; 

extern string  AwesomeFilter2="=== Awesome 2 Filter ===";
extern bool       bUseAwesome_2       =  false;    //if true the ea uses Awesome;
extern int        AwesomeTF_2         =  0;       //Awesome timeframe in minutes: 0 - current tf;
extern int        AwesomeShift_2      =  1; 




string THVTrixFilter1 = "=== THVTrix Filter ===";

bool       bTHVTrix_Filter = false;
int        iTHVTrix_TimeFrame  = 0; // Applied timeframe. if 0 -- current
int        iTHVTrix_Shift  = 1; // >= 0
bool       bTHVTrix_FilterExit = false;
int        iTHVTrix_TimeFrameExit  = 0; // Applied timeframe. if 0 -- current
int        iTHVTrix_ShiftExit  = 1; // >= 0

extern string FX_Secret_Exit        = "=== FX_Secret Exit ===";
extern bool       bUseFX_Secret_Exit        =   true; //if true the ea will use XO_A_H exit;
extern int        iFX_Secret_TimeFrameExit  = 0; // Applied timeframe. if 0 -- current
extern int        iFX_Secret_ShiftExit      = 1;
extern int        iFX_Secret_FastslowExit = 7;
extern int        iFX_Secret_DisplayExit = 999;

extern string FX_Secret_Filter = "=== FX_Secret Filter ===";

extern bool       bFX_Secret_Filter = false;
extern int        iFX_Secret_TimeFrame      = 0; // Applied timeframe. if 0 -- current
extern int        iFX_Secret_Shift          = 1;
extern int        iFX_Secret_Fastslow = 7;
extern int        iFX_Secret_Display = 999;

extern string FX_Secret2_Filter = "=== FX_Secret2 Filter ===";

extern bool       bFX_Secret2_Filter        = false;
extern int        iFX_Secret2_TimeFrame     = 0; // Applied timeframe. if 0 -- current
extern int        iFX_Secret2_Shift          = 1;
extern int        iFX_Secret2_Fastslow = 7;
extern int        iFX_Secret2_Display = 999;

extern string FX_Secret3_Filter = "=== FX_Secret3 Filter ===";

extern bool       bFX_Secret3_Filter        = false;
extern int        iFX_Secret3_TimeFrame     = 0; // Applied timeframe. if 0 -- current
extern int        iFX_Secret3_Shift          = 1;
extern int        iFX_Secret3_Fastslow = 7;
extern int        iFX_Secret3_Display = 999;

extern string FX_Secret4_Filter = "=== FX_Secret4 Filter ===";

extern bool       bFX_Secret4_Filter        = false;
extern int        iFX_Secret4_TimeFrame     = 0; // Applied timeframe. if 0 -- current
extern int        iFX_Secret4_Shift          = 1;
extern int        iFX_Secret4_Fastslow = 7;
extern int        iFX_Secret4_Display = 999;

extern string WPR_Filter = "=== WPR Filter ===";

extern bool       bWPR_Filter = false;
extern int        iWPR_TimeFrame      = 0; // Applied timeframe. if 0 -- current
extern int        iWPR_Period           = 27;
extern int        iWPR_UpLevel        = -20;
extern int        iWPR_DnLevel        = -80;
extern int        iWPR_Shift          = 1;

int i,bc=-1,lastorder;
double buyorderprofit,sellorderprofit;
int nstarthour,nendhour,nfridayhour,tpb,tps,cnt,ticket;
double lastbuyopenprice,lastsellopenprice,lastbuyprofit,lastsellprofit;
double ask,bid,cb,sl,tp,ilots,lastbuylot,lastselllot,lastlot,lastprofit,mlots;
string istarthour,istartminutes,iendhour,iendminutes,ifridayhour,ifridayminutes;
datetime t0,t1,tstart,tend,tfriday,lastbuyopentime,lastsellopentime;

int iEnabledNLDTrend = -1;
datetime LastNLDTTrendCheck;
datetime LastSDLTimeCheck;

double pt,mt;
int dg;

int init()
{

   if(lot_increase && lot_decrease) {lot_increase = false;}
   
   if (iNLDTimeFrame1 == 0) iNLDTimeFrame1 = Period();
   if (iNLDTimeFrame2 == 0) iNLDTimeFrame2 = Period();
   
   t0 = Time[0];
   t1 = Time[0];
   dg = Digits;
   if(dg == 3 || dg == 5)
   {
      pt = Point * 10;
      mt = 10;
   }
   else
   {
      pt = Point;
      mt = 1;
   }
   dtQQEEntryCross = Time[0];
   return(0);
}

int start(){

   RefreshRates();
   ask=MarketInfo(Symbol(),MODE_ASK);
   bid=MarketInfo(Symbol(),MODE_BID);

   if(breakevengain>0)movebreakeven(breakevengain,breakeven);
   if(trailingstop>0)movetrailingstop(trailingstart,trailingstop);
   if(trailingprofit>0)movetrailingprofit(trailingstart,trailingprofit);
   
   buyorderprofit = 0;
   sellorderprofit = 0;
   int iOpenOrders = 0;
   datetime bar_open_time = iTime(Symbol(),Period(),0);
   tpb = 0; tps = 0;
   if(OrdersTotal() > 0)
   {
      for(i = 0;i < OrdersTotal();i++)
      {
         if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
         {
            if(OrderSymbol()==Symbol() && OrderMagicNumber()==magic && OrderCloseTime()==0)
            {
               if(OrderType()==OP_BUY)
               {
                  if(OrderOpenTime() >= bar_open_time) {tpb++;}
                  
                  buyorderprofit = buyorderprofit + NormalizeDouble(OrderProfit() + OrderSwap(),2);
                  iOpenOrders++;
               }
               if(OrderType()==OP_SELL)
               {
                  if(OrderOpenTime() >= bar_open_time) {tps++;}
                  
                  sellorderprofit = sellorderprofit + NormalizeDouble(OrderProfit() + OrderSwap(),2);
                  iOpenOrders++;
               }
            }
         }
      }
   }

   double lotincsize = 0;
   //double lotdecsize = 0;
   if(basket_amount && (buyorderprofit + sellorderprofit) >= profit || (buyorderprofit + sellorderprofit) <= -1 * loss)
   {
      closebuy();
      closesell();
   }
   else if(lot_increase == true && lot_decrease == false)
   {
      lotincsize = iOpenOrders * lot_inc_size;
   }
   else if(lot_decrease == true && lot_increase == false)
   {
      lotincsize = -1.00 * iOpenOrders * lot_dec_size;
   }
   
   if (goldminerentry)
   {
      double gred=iCustom(NULL,0,"goldminer1",grisk,countbars,0,goldminershift);
      double ggreen=iCustom(NULL,0,"goldminer1",grisk,countbars,1,goldminershift);
   }

   if(nonlagmafilter)
   {
      double fnlmy=iCustom(NULL,0,"NonLagMA_v6",price,length,displace,filter2,clr,colorbarback,deviation,0,nonlagmashift);
      double fnlmg=iCustom(NULL,0,"NonLagMA_v6",price,length,displace,filter2,clr,colorbarback,deviation,1,nonlagmashift);
      double fnlmr=iCustom(NULL,0,"NonLagMA_v6",price,length,displace,filter2,clr,colorbarback,deviation,2,nonlagmashift);
   }
   if(nonlagmaexit)
   {
      double nlmy=iCustom(NULL,0,"NonLagMA_v6",price2,length2,displace2,filter22,clr2,colorbarback2,deviation2,0,nonlagmashift);
      double nlmg=iCustom(NULL,0,"NonLagMA_v6",price2,length2,displace2,filter22,clr2,colorbarback2,deviation2,1,nonlagmashift);
      double nlmr=iCustom(NULL,0,"NonLagMA_v6",price2,length2,displace2,filter22,clr2,colorbarback2,deviation2,2,nonlagmashift);

      double nlmya=iCustom(NULL,0,"NonLagMA_v6",price2,length2,displace2,filter22,clr2,colorbarback2,deviation2,0,nonlagmashift+1);
      double nlmga=iCustom(NULL,0,"NonLagMA_v6",price2,length2,displace2,filter22,clr2,colorbarback2,deviation2,1,nonlagmashift+1);
      double nlmra=iCustom(NULL,0,"NonLagMA_v6",price2,length2,displace2,filter22,clr2,colorbarback2,deviation2,2,nonlagmashift+1);
   }
   if(slopelinefilter)
   {
      double sdl=iCustom(NULL,sdltimeframe,"Slope Direction Line",period,method,sdlprice,2,sdlshift);
      double sdla=iCustom(NULL,sdltimeframe,"Slope Direction Line",period,method,sdlprice,2,sdlshift+1);
   }
   
   if(slopelinefilter_1)
   {
      double sdl_1=iCustom(NULL,sdltimeframe_1,"Slope Direction Line",period_1,method_1,sdlprice_1,2,sdlshift_1);
      double sdla_1=iCustom(NULL,sdltimeframe_1,"Slope Direction Line",period_1,method_1,sdlprice_1,2,sdlshift_1+1);
   }
   
   if(damianifilter)
   {
      double dafgy=iCustom(NULL,damianitimeframe,"Damiani_volatmeter",Viscosity,Sedimentation,Threshold_level,lag_supressor,0,damianishift);
      double dafgn=iCustom(NULL,damianitimeframe,"Damiani_volatmeter",Viscosity,Sedimentation,Threshold_level,lag_supressor,2,damianishift);
   }
   
   bool NLDExitBuysSignal = false;
   bool NLDExitSellsSignal = false;
   
   if(bSdlMamExit)
   {
      int nSdl_signal=Signal();
      
      if (nSdl_signal==1) NLDExitSellsSignal = true;
      if (nSdl_signal==-1) NLDExitBuysSignal = true;
   }
   
   bool  NonLagDotCloseBuy=false;
   bool  NonLagDotCloseSell=false;
   
   if(bNonLagDotExit)   {
      double nld_[2];
      nld_[0]=iCustom(Symbol(),NLDExitTF,"nonlagdot",Price,Length,Displace,Filter,Color,ColorBarBack,Deviation,1,1);
      nld_[1]=iCustom(Symbol(),NLDExitTF,"nonlagdot",Price,Length,Displace,Filter,Color,ColorBarBack,Deviation,1,2);
      
      if((nld_[0]!=0 && nld_[0]!=EMPTY_VALUE) && (nld_[1]==0 || nld_[1]==EMPTY_VALUE)) NonLagDotCloseSell=true;
      if((nld_[0]==0 || nld_[0]==EMPTY_VALUE) && (nld_[1]!=0 && nld_[1]!=EMPTY_VALUE))NonLagDotCloseBuy=true;     
   }   
   
// qqe exit

   bool  qqeExitBuy  =  false,
         qqeExitSell =  false;   
   
   if(QqeExit) {
      int   qqe_exit_1 = QqeSignal(QqeExitTimeframe, QqeExitSf, QqeExitRsiPeriod, QqeExitShift),
            qqe_exit_2 = QqeSignal(QqeExitTimeframe, QqeExitSf, QqeExitRsiPeriod, QqeExitShift + 1);
            
      if(qqe_exit_2 == OP_SELL && qqe_exit_1 == OP_BUY) qqeExitSell = true;
      if(qqe_exit_2 == OP_BUY && qqe_exit_1 == OP_SELL) qqeExitBuy = true;
   }
   

//-----------------------------------
   if(bALF_Ultimate) {
      bool ALF_UltimateCanBuy=false;
      bool ALF_UltimateCanSell=false;
      
      double alf_ultimate=iCustom(Symbol(),ALF_UltimateTF,"ALF_Ultimate Filter_v1",0,0,0,1,0,KPeriod,DPeriod,SPeriod,MAMode,MAPrice,BuyAlertLevel,SellAlertLevel,2,1);
     
      if(alf_ultimate>0)ALF_UltimateCanBuy=true;
      if(alf_ultimate<0)ALF_UltimateCanSell=true;
   }
   
   if(bUseAwesome)   {
      bool  AwesomeCanBuy=false;
      bool  AwesomeCanSell=false;
      
      double ao[2];
      ao[0]=iAO(Symbol(),AwesomeTF,AwesomeShift);
      ao[1]=iAO(Symbol(),AwesomeTF,AwesomeShift+1);
      
      if(ao[0]>ao[1] && ao[0]>0) AwesomeCanBuy=true;
      if(ao[0]<ao[1] && ao[0]<0) AwesomeCanSell=true;
   }
   
   
   if(bUseAwesome_1)   {
      bool  Awesome1CanBuy=false;
      bool  Awesome1CanSell=false;
      
      double ao_1[2];
      ao_1[0]=iAO(Symbol(),AwesomeTF_1,AwesomeShift_1);
      ao_1[1]=iAO(Symbol(),AwesomeTF_1,AwesomeShift_1+1);
      
      if(ao_1[0]>ao_1[1] && ao_1[0]>0) Awesome1CanBuy=true;
      if(ao_1[0]<ao_1[1] && ao_1[0]<0) Awesome1CanSell=true;
   }
   
   if(bUseAwesome_2)   {
      bool  Awesome2CanBuy=false;
      bool  Awesome2CanSell=false;
      
      double ao_2[2];
      ao_2[0]=iAO(Symbol(),AwesomeTF_2,AwesomeShift_2);
      ao_2[1]=iAO(Symbol(),AwesomeTF_2,AwesomeShift_2+1);
      
      if(ao_2[0]>ao_2[1] && ao_2[0]>0) Awesome2CanBuy=true;
      if(ao_2[0]<ao_2[1] && ao_2[0]<0) Awesome2CanSell=true;
   }
   
   
   
   int    iSlopeDirectionEntry  = EMPTY_VALUE;
   
   if(bSlopeDirectionEntry) {
      int SlopeDirectionSignalNow=SignalSDL("0", iSlopeDirectionEntry_TimeFrame, iSlopeDirectionEntryPeriod, iSlopeDirectionEntryMethod, iSlopeDirectionEntryPrice, iSlopeDirectionEntryShift);
      
      if(SlopeDirectionSignalNow==-1) iSlopeDirectionEntry=OP_SELL;
      if(SlopeDirectionSignalNow==1) iSlopeDirectionEntry=OP_BUY;
   }
   
   bool SlopeDirectionCloseBuySignal=false;
   bool SlopeDirectionCloseSellSignal=false;
   
   if(bSlopeDirectionExit) {
      SlopeDirectionSignalNow=SignalSDL("0", iSlopeDirection_TimeFrame, iSlopeDirectionPeriod, iSlopeDirectionMethod, iSlopeDirectionPrice, iSlopeDirectionExitShift, true);
      
      if(SlopeDirectionSignalNow==-1)SlopeDirectionCloseBuySignal=true;
      if(SlopeDirectionSignalNow==1)SlopeDirectionCloseSellSignal=true;
   }      
   
   // === QQE ==============================================================================================

   double dQQE_0_0   = 0;
   double dQQE_1_0   = 0;
   double dQQE_0_1   = 0;
   double dQQE_1_1   = 0;
   int    iQQEEntry  = EMPTY_VALUE;
   int    iQQEFilter = EMPTY_VALUE;
      
   if(bQQEEntry)
   {
      dQQE_0_0 = iCustom(Symbol(),iQQEEntryTimeframe,"QQE",iQQEEntry_SF,iQQEEntry_RSI_Period,0,iQQEEntryShift);
      dQQE_1_0 = iCustom(Symbol(),iQQEEntryTimeframe,"QQE",iQQEEntry_SF,iQQEEntry_RSI_Period,1,iQQEEntryShift);
      dQQE_0_1 = iCustom(Symbol(),iQQEEntryTimeframe,"QQE",iQQEEntry_SF,iQQEEntry_RSI_Period,0,iQQEEntryShift + 1);
      dQQE_1_1 = iCustom(Symbol(),iQQEEntryTimeframe,"QQE",iQQEEntry_SF,iQQEEntry_RSI_Period,1,iQQEEntryShift + 1);
      
      if(dQQE_0_1 > dQQE_1_1 && dQQE_0_0 < dQQE_1_0 && Time[0] > dtQQEEntryCross)
      {
         dtQQEEntryCross = Time[0];
         iQQEEntry = OP_SELL;
      }
      else if(dQQE_0_1 < dQQE_1_1 && dQQE_0_0 > dQQE_1_0 && Time[0] > dtQQEEntryCross)
      {
         dtQQEEntryCross = Time[0];
         iQQEEntry = OP_BUY;
      }
      else
      {
         iQQEEntry = -1;
      }
   }  
   if(bQQEFilter)
   {
      dQQE_0_0 = iCustom(Symbol(),iQQEFilterTimeframe,"QQE",iQQEFilter_SF,iQQEFilter_RSI_Period,0,iQQEFilterShift);
      dQQE_1_0 = iCustom(Symbol(),iQQEFilterTimeframe,"QQE",iQQEFilter_SF,iQQEFilter_RSI_Period,1,iQQEFilterShift);
      
      if(dQQE_0_0 > dQQE_1_0)
      {
         iQQEFilter = OP_BUY;
      }
      else if(dQQE_0_0 < dQQE_1_0)
      {
         iQQEFilter = OP_SELL;
      }
      else
      {
         iQQEFilter = -1;
      }
   }
   
   
// QQE filter 1
   int iQqeFilter_1 = EMPTY_VALUE;
   if(QqeFilter_1)   {
      iQqeFilter_1 = QqeSignal(QqeTimeframe_1, QqeSf_1, QqeRsiPeriod_1, QqeShift_1);
   }
   
   int iQqeFilter_2 = EMPTY_VALUE;
   if(QqeFilter_2)   {
      iQqeFilter_2 = QqeSignal(QqeTimeframe_2, QqeSf_2, QqeRsiPeriod_2, QqeShift_2);
   }
   
//=== Arrow RSI ====================================//
   int ArrowRSIOpen=0;
   if(UseArrowRsiEntry) {
      int rsi_signal=SignalRSI();

      if(rsi_signal==1)ArrowRSIOpen=1;
      if(rsi_signal==-1) ArrowRSIOpen=-1;
   }   
   
   
   // === NonLagDot ==============================================================================================
   
   int NLDEntryDirection;
   int lastNLDEntryDirection;   
   
   
   if (bNonLagDotEntry)
   {
      double NLDEup = iCustom(Symbol(), iNLDEntryTimeFrame, "nonlagdot", iNLDEntryPrice, iNLDEntryLength, 0, iNLDEntryFilter, 1, 0, 0, 1, iNLDEntryShift);
      double NLDEdn = iCustom(Symbol(), iNLDEntryTimeFrame, "nonlagdot", iNLDEntryPrice, iNLDEntryLength, 0, iNLDEntryFilter, 1, 0, 0, 2, iNLDEntryShift);
      double lastNLDEup = iCustom(Symbol(), iNLDEntryTimeFrame, "nonlagdot", iNLDEntryPrice, iNLDEntryLength, 0, iNLDEntryFilter, 1, 0, 0, 1, iNLDEntryShift + 1);
      double lastNLDEdn = iCustom(Symbol(), iNLDEntryTimeFrame, "nonlagdot", iNLDEntryPrice, iNLDEntryLength, 0, iNLDEntryFilter, 1, 0, 0, 2, iNLDEntryShift + 1);

      if (Fits(NLDEup)) NLDEntryDirection = OP_BUY;
      if (Fits(NLDEdn)) NLDEntryDirection = OP_SELL;

      if (Fits(lastNLDEup)) lastNLDEntryDirection = OP_BUY;
      if (Fits(lastNLDEdn)) lastNLDEntryDirection = OP_SELL;
      
      
      if (!bNonLagDotEnterAlways && NLDEntryDirection != lastNLDEntryDirection && LastNLDTTrendCheck != Time[0])
      {
         iEnabledNLDTrend = NLDEntryDirection;
         LastNLDTTrendCheck = Time[0];
      }      
   }
   
   int NLD1Direction;
      
   if (bnonLagDotFilter1)
   {
      NLD1Direction = -1;
      double NLD1up = iCustom(Symbol(), iNLDTimeFrame1, "nonlagdot", iNLDPrice1, iNLDLength1, 0, iNLDFilter1, 1, 0, 0, 1, iNLDShift1);
      double NLD1dn = iCustom(Symbol(), iNLDTimeFrame1, "nonlagdot", iNLDPrice1, iNLDLength1, 0, iNLDFilter1, 1, 0, 0, 2, iNLDShift1);
      
      if (Fits(NLD1up)) NLD1Direction = OP_BUY;
      if (Fits(NLD1dn)) NLD1Direction = OP_SELL;
   }

   int NLD2Direction;

   if (bnonLagDotFilter2)
   {
      NLD2Direction = -1;
      double NLD2up = iCustom(Symbol(), iNLDTimeFrame2, "nonlagdot", iNLDPrice2, iNLDLength2, 0, iNLDFilter2, 1, 0, 0, 1, iNLDShift2);
      double NLD2dn = iCustom(Symbol(), iNLDTimeFrame2, "nonlagdot", iNLDPrice2, iNLDLength2, 0, iNLDFilter2, 1, 0, 0, 2, iNLDShift2);
      
      if (Fits(NLD2up)) NLD2Direction = OP_BUY;
      if (Fits(NLD2dn)) NLD2Direction = OP_SELL;
   }
   
   int SuperTrendDirection;
   
   if (bSuperTrendFilter)
   {
      double up = iCustom(Symbol(), iSTTimeFrame, "Supertrend1", 0, iSTShift);
      double dn = iCustom(Symbol(), iSTTimeFrame, "Supertrend1", 1, iSTShift);
      
      if (Fits(up)) SuperTrendDirection = OP_BUY;
      if (Fits(dn)) SuperTrendDirection = OP_SELL;
   }
   
   bool XO_A_H_CanBuy = false;
   bool XO_A_H_CanSell = false;
   
   if (bXO_A_H_Filter)
   {
      double XO_A_Hup = iCustom(Symbol(), iXO_A_H_TimeFrame, "XO_A_H", iXO_A_H_BoxSize, 0, iXO_A_H_Shift);
      double XO_A_Hdn = iCustom(Symbol(), iXO_A_H_TimeFrame, "XO_A_H", iXO_A_H_BoxSize, 1, iXO_A_H_Shift);
      
      if (XO_A_Hup >= iXO_A_H_UpLevel) XO_A_H_CanBuy = true;
      if (XO_A_Hdn <= iXO_A_H_DnLevel) XO_A_H_CanSell = true;
   }
   
   bool XO_A_H2_CanBuy = false;
   bool XO_A_H2_CanSell = false;
   
   if (bXO_A_H2_Filter)
   {
      double XO_A_H2up = iCustom(Symbol(), iXO_A_H2_TimeFrame, "XO_A_H", iXO_A_H2_BoxSize, 0, iXO_A_H2_Shift);
      double XO_A_H2dn = iCustom(Symbol(), iXO_A_H2_TimeFrame, "XO_A_H", iXO_A_H2_BoxSize, 1, iXO_A_H2_Shift);
      
      if (XO_A_H2up >= iXO_A_H2_UpLevel) XO_A_H2_CanBuy = true;
      if (XO_A_H2dn <= iXO_A_H2_DnLevel) XO_A_H2_CanSell = true;
   }
   
   bool XO_A_H3_CanBuy = false;
   bool XO_A_H3_CanSell = false;
   
   if (bXO_A_H3_Filter)
   {
      double XO_A_H3up = iCustom(Symbol(), iXO_A_H3_TimeFrame, "XO_A_H", iXO_A_H3_BoxSize, 0, iXO_A_H3_Shift);
      double XO_A_H3dn = iCustom(Symbol(), iXO_A_H3_TimeFrame, "XO_A_H", iXO_A_H3_BoxSize, 1, iXO_A_H3_Shift);
      
      if (XO_A_H3up >= iXO_A_H3_UpLevel) XO_A_H3_CanBuy = true;
      if (XO_A_H3dn <= iXO_A_H3_DnLevel) XO_A_H3_CanSell = true;
   }
   
   bool XO_A_H4_CanBuy = false;
   bool XO_A_H4_CanSell = false;
   
   if (bXO_A_H4_Filter)
   {
      double XO_A_H4up = iCustom(Symbol(), iXO_A_H4_TimeFrame, "XO_A_H", iXO_A_H4_BoxSize, 0, iXO_A_H4_Shift);
      double XO_A_H4dn = iCustom(Symbol(), iXO_A_H4_TimeFrame, "XO_A_H", iXO_A_H4_BoxSize, 1, iXO_A_H4_Shift);
      
      if (XO_A_H4up >= iXO_A_H4_UpLevel) XO_A_H4_CanBuy = true;
      if (XO_A_H4dn <= iXO_A_H4_DnLevel) XO_A_H4_CanSell = true;
   }
   
//=== XO_A_H exit ===//
   bool XO_A_H_CloseBuy=false;
   bool  XO_A_H_CloseSell=false;
   
   if(bUseXO_A_H_Exit)  {
      double xoah_up[2];
      double xoah_dn[2];
      
      xoah_up[0] = iCustom(Symbol(), iXO_A_H_TimeFrameExit, "XO_A_H", iXO_A_H_BoxSizeExit, 0, 1);
      xoah_up[1] = iCustom(Symbol(), iXO_A_H_TimeFrameExit, "XO_A_H", iXO_A_H_BoxSizeExit, 0, 2);
      
      xoah_dn[0] = iCustom(Symbol(), iXO_A_H_TimeFrameExit, "XO_A_H", iXO_A_H_BoxSizeExit, 1, 1);
      xoah_dn[1] = iCustom(Symbol(), iXO_A_H_TimeFrameExit, "XO_A_H", iXO_A_H_BoxSizeExit, 1, 2);
      
      if(xoah_up[1]==0 && xoah_up[0]>0)XO_A_H_CloseSell=true;
      if(xoah_dn[1]==0 && xoah_dn[0]<0)XO_A_H_CloseBuy=true;
                        
   }  
   
//=== THVTrix entry ===//    
   
   bool THVTrix_CanBuy = false;
   bool THVTrix_CanSell = false;
   
   if (bTHVTrix_Filter)
   {
      double THVTrix_up[2];
      double THVTrix_dn[2];
      THVTrix_up[0] = iCustom(Symbol(), iTHVTrix_TimeFrame, "THV4 Trix V1.2", 2, iTHVTrix_Shift);
      THVTrix_up[1] = iCustom(Symbol(), iTHVTrix_TimeFrame, "THV4 Trix V1.2", 2, iTHVTrix_Shift + 1);
      
      THVTrix_dn[0] = iCustom(Symbol(), iTHVTrix_TimeFrame, "THV4 Trix V1.2", 3, iTHVTrix_Shift);
      THVTrix_dn[1] = iCustom(Symbol(), iTHVTrix_TimeFrame, "THV4 Trix V1.2", 3, iTHVTrix_Shift + 1);
      
      if (THVTrix_up[1]==EMPTY_VALUE && THVTrix_up[0] != EMPTY_VALUE) THVTrix_CanBuy = true;
      if (THVTrix_dn[1]==EMPTY_VALUE && THVTrix_dn[0] != EMPTY_VALUE) THVTrix_CanSell = true;
   }
      
   
   bool THVTrix_CloseBuy=false;
   bool THVTrix_CloseSell=false;
   
   if (bTHVTrix_FilterExit)
   {
      THVTrix_up[0] = iCustom(Symbol(), iTHVTrix_TimeFrameExit, "THV4 Trix V1.2", 2, iTHVTrix_ShiftExit);
      THVTrix_up[1] = iCustom(Symbol(), iTHVTrix_TimeFrameExit, "THV4 Trix V1.2", 2, iTHVTrix_ShiftExit + 1);
      
      THVTrix_dn[0] = iCustom(Symbol(), iTHVTrix_TimeFrameExit, "THV4 Trix V1.2", 3, iTHVTrix_ShiftExit);
      THVTrix_dn[1] = iCustom(Symbol(), iTHVTrix_TimeFrameExit, "THV4 Trix V1.2", 3, iTHVTrix_ShiftExit + 1);
      
      if (THVTrix_up[1]==EMPTY_VALUE && THVTrix_up[0] != EMPTY_VALUE) THVTrix_CloseSell = true;
      if (THVTrix_dn[1]==EMPTY_VALUE && THVTrix_dn[0] != EMPTY_VALUE) THVTrix_CloseBuy = true;
   }
   
   
   //=== FX_Secret entry ===//
   bool FX_Secret_CanBuy = false;
   bool FX_Secret_CanSell = false;
   
   if (bFX_Secret_Filter)
   {
      double FX_Secret_Val = iCustom(Symbol(), iFX_Secret_TimeFrame, "fxsecretsignal", iFX_Secret_Fastslow, iFX_Secret_Display, 0, iFX_Secret_Shift);
      
      if (FX_Secret_Val > 0) FX_Secret_CanBuy = true;
      if (FX_Secret_Val < 0) FX_Secret_CanSell = true;
      
   }
   
   bool FX_Secret2_CanBuy = false;
   bool FX_Secret2_CanSell = false;
   
   if (bFX_Secret2_Filter)
   {
      FX_Secret_Val = iCustom(Symbol(), iFX_Secret2_TimeFrame, "fxsecretsignal", iFX_Secret2_Fastslow, iFX_Secret2_Display, 0, iFX_Secret2_Shift);
      
      if (FX_Secret_Val > 0) FX_Secret2_CanBuy = true;
      if (FX_Secret_Val < 0) FX_Secret2_CanSell = true;
      
   }
   
   bool FX_Secret3_CanBuy = false;
   bool FX_Secret3_CanSell = false;
   
   if (bFX_Secret3_Filter)
   {
      FX_Secret_Val = iCustom(Symbol(), iFX_Secret3_TimeFrame, "fxsecretsignal", iFX_Secret3_Fastslow, iFX_Secret3_Display, 0, iFX_Secret3_Shift);
      
      if (FX_Secret_Val > 0) FX_Secret3_CanBuy = true;
      if (FX_Secret_Val < 0) FX_Secret3_CanSell = true;
      
   }
   
   bool FX_Secret4_CanBuy = false;
   bool FX_Secret4_CanSell = false;
   
   if (bFX_Secret4_Filter)
   {
      FX_Secret_Val = iCustom(Symbol(), iFX_Secret4_TimeFrame, "fxsecretsignal", iFX_Secret4_Fastslow, iFX_Secret4_Display, 0, iFX_Secret4_Shift);
      
      if (FX_Secret_Val > 0) FX_Secret4_CanBuy = true;
      if (FX_Secret_Val < 0) FX_Secret4_CanSell = true;
      
   }

//=== WPR filter ===//
   
   bool WPR_CanBuy = false;
   bool WPR_CanSell = false;
   
   if (bWPR_Filter)
   {
      double WPR_Val = iWPR(Symbol(), iWPR_TimeFrame, iWPR_Period, iWPR_Shift);
      
      if (WPR_Val < iWPR_DnLevel) 
      {
           WPR_CanBuy = true;
      }
      else if (WPR_Val > iWPR_UpLevel)
      {
           WPR_CanSell = true;   
      }
      else
      {
           WPR_CanBuy = true;
           WPR_CanSell = true;
      }         
   }
   
//=== FX_Secret exit ===//
   bool FX_Secret_CloseBuy=false;
   bool FX_Secret_CloseSell=false;
   
   if (bUseFX_Secret_Exit)
   {
      double FX_Secret_ValS[2];
      FX_Secret_ValS[0] = iCustom(Symbol(), iFX_Secret_TimeFrameExit, "fxsecretsignal", iFX_Secret_FastslowExit, iFX_Secret_DisplayExit, 0, iFX_Secret_ShiftExit);
      FX_Secret_ValS[1] = iCustom(Symbol(), iFX_Secret_TimeFrameExit, "fxsecretsignal", iFX_Secret_FastslowExit, iFX_Secret_DisplayExit, 0, iFX_Secret_ShiftExit + 1);
      
      if (FX_Secret_ValS[1] < 0 && FX_Secret_ValS[0] >= 0) FX_Secret_CloseSell = true;
      if (FX_Secret_ValS[1] > 0 && FX_Secret_ValS[0] <= 0) FX_Secret_CloseBuy = true;
   }

    
//=====================================//   
   bool buy  = false;
   bool sell = false;
   int wpr_filter_signal = WPRSignal();
   int wpr_filter_signal_1 = WPRSignal_1();
   

   if(
      (
            (goldminerentry  && ggreen     >  0      && ggreen != EMPTY_VALUE)
         || (bQQEEntry       && iQQEEntry  == OP_BUY                         )
         || (ArrowRSIOpen==1                                            )
         || (bNonLagDotEntry && NLDEntryDirection == OP_BUY && (lastNLDEntryDirection == OP_SELL || bNonLagDotEnterAlways))
         || (bTHVTrix_Filter && THVTrix_CanBuy)
         || (bSlopeDirectionEntry && iSlopeDirectionEntry  == OP_BUY)
      )
      && (nonlagmafilter  == false || (nonlagmafilter  && fnlmg      <  350))
      && (slopelinefilter == false || (slopelinefilter && sdl        >  sdla))
      // new sdl filter
      && (slopelinefilter_1 == false || (slopelinefilter_1 && sdl_1        >  sdla_1))
      && (damianifilter   == false || (damianifilter   && dafgy      <  dafgn))
      && (bQQEFilter      == false || (bQQEFilter      && iQQEFilter == OP_BUY))
      // qqe filter 1
      && (QqeFilter_1      == false || (QqeFilter_1      && iQqeFilter_1 == OP_BUY))
      // qqe filter 2
      && (QqeFilter_2      == false || (QqeFilter_2      && iQqeFilter_2 == OP_BUY))
      
      && (bnonLagDotFilter1==false || NLD1Direction == OP_BUY)
      && (bnonLagDotFilter2==false || NLD2Direction == OP_BUY)
      && (bSuperTrendFilter==false || SuperTrendDirection == OP_BUY)
      && (bXO_A_H_Filter  == false || XO_A_H_CanBuy)
      && (bXO_A_H2_Filter == false || XO_A_H2_CanBuy)
      && (bXO_A_H3_Filter == false || XO_A_H3_CanBuy)
      && (bXO_A_H4_Filter == false || XO_A_H4_CanBuy)
      && (bALF_Ultimate   == false || ALF_UltimateCanBuy)
      && (bUseAwesome     == false || AwesomeCanBuy)    
      && (bUseAwesome_1     == false || Awesome1CanBuy)    
      && (bUseAwesome_2     == false || Awesome2CanBuy)    
      && (bFX_Secret_Filter  == false || FX_Secret_CanBuy)
      && (bFX_Secret2_Filter == false || FX_Secret2_CanBuy)  
      && (bFX_Secret3_Filter == false || FX_Secret3_CanBuy)  
      && (bFX_Secret4_Filter == false || FX_Secret4_CanBuy)  
      && (bWPR_Filter        == false || WPR_CanBuy) 
      && (WPR_Direction_Filter   == false || wpr_filter_signal == OP_BUY) 
      && (WPR_Direction_Filter_1 == false || wpr_filter_signal_1 == OP_BUY) 
   )
   {
      if(reversesignals)
      {
         sell = true;
      }
      else
      {
         buy = true;
      }
   }
   
   
   if(
      (
            (goldminerentry  && gred       >  0       && gred != EMPTY_VALUE)
         || (bQQEEntry       && iQQEEntry  == OP_SELL                       )
         || (ArrowRSIOpen==-1                                          )
         || (bNonLagDotEntry && NLDEntryDirection == OP_SELL && (lastNLDEntryDirection == OP_BUY || bNonLagDotEnterAlways))
         || (bTHVTrix_Filter && THVTrix_CanSell)
         || (bSlopeDirectionEntry && iSlopeDirectionEntry  == OP_SELL)
      )
      && (nonlagmafilter  == false || (nonlagmafilter  && fnlmr      <  350))
      && (slopelinefilter == false || (slopelinefilter && sdl        <  sdla))
      // new sdl filter
      && (slopelinefilter_1 == false || (slopelinefilter_1 && sdl_1        <  sdla_1))
      && (damianifilter   == false || (damianifilter   && dafgy      <  dafgn))
      && (bQQEFilter      == false || (bQQEFilter      && iQQEFilter == OP_SELL))
      // qqe filter 1
      && (QqeFilter_1      == false || (QqeFilter_1      && iQqeFilter_1 == OP_SELL))
      // qqe filter 2
      && (QqeFilter_2      == false || (QqeFilter_2      && iQqeFilter_2 == OP_SELL))
      
      && (bnonLagDotFilter1==false || NLD1Direction == OP_SELL)
      && (bnonLagDotFilter2==false || NLD2Direction == OP_SELL)
      && (bSuperTrendFilter==false || SuperTrendDirection == OP_SELL)
      && (bXO_A_H_Filter  == false || XO_A_H_CanSell)
      && (bXO_A_H2_Filter == false || XO_A_H2_CanSell)
      && (bXO_A_H3_Filter == false || XO_A_H3_CanSell)
      && (bXO_A_H4_Filter == false || XO_A_H4_CanSell)
      && (bALF_Ultimate   == false || ALF_UltimateCanSell)
      && (bUseAwesome     == false || AwesomeCanSell)   
      && (bUseAwesome_1     == false || Awesome1CanSell)   
      && (bUseAwesome_2     == false || Awesome2CanSell)   
      && (bFX_Secret_Filter  == false || FX_Secret_CanSell)
      && (bFX_Secret2_Filter == false || FX_Secret2_CanSell)  
      && (bFX_Secret3_Filter == false || FX_Secret3_CanSell)   
      && (bFX_Secret4_Filter == false || FX_Secret4_CanSell)    
      && (bWPR_Filter        == false || WPR_CanSell)   
      && (WPR_Direction_Filter   == false || wpr_filter_signal == OP_SELL) 
      && (WPR_Direction_Filter_1 == false || wpr_filter_signal_1 == OP_SELL) 
   )
   {
      /*type = -1;
      if (OrderSelect(GetLastHstTicket(), SELECT_BY_TICKET, MODE_HISTORY))
      {
         type = OrderType();
      }*/

      if(reversesignals)
      {
         /*if (type != OP_BUY)*/ buy = true;
      }
      else
      {
         /*if (type != OP_SELL)*/ sell = true;
      }
   }

   string strComment = "";
   if(/*goldminerentry || arrowzagentry || */bQQEEntry)
   {
      strComment = StringConcatenate(strComment,"\nEntry:");
      if(bQQEEntry)
      {
         strComment = StringConcatenate(strComment,"\nQQE: ",buyOrSell(iQQEEntry));
      }
      strComment = StringConcatenate(strComment,"\n");
   }
   
   if(bNonLagDotEntry)
   {
      strComment = StringConcatenate(strComment,"\nEntry:");
      if (NLDEntryDirection != lastNLDEntryDirection || bNonLagDotEnterAlways)
      {
         strComment = StringConcatenate(strComment, "\nNonLagDot: ", buyOrSell(NLDEntryDirection));
      }
      else if (!bNonLagDotEnterAlways)
      {
         strComment = StringConcatenate(strComment, "\nNonLagDot: ", buyOrSell(iEnabledNLDTrend));
      }
      else
      {
         strComment = StringConcatenate(strComment, "\nNonLagDot: No Signal");
      }
      strComment = StringConcatenate(strComment,"\n");
   }

   if(bQQEFilter)
   {
      strComment = StringConcatenate(strComment,"\nFilter:");
      strComment = StringConcatenate(strComment,"\nQQE: ",buyOrSell(iQQEFilter));
      strComment = StringConcatenate(strComment,"\n");
   }
   
   if(bnonLagDotFilter1)
   {
      strComment = StringConcatenate(strComment,"\nFilter:\nNonLagDotQQE ", TFToStr(iNLDTimeFrame1), ": ", buyOrSell(NLD1Direction), "\n");
   }
   
   if(bnonLagDotFilter2)
   {
      strComment = StringConcatenate(strComment,"\nFilter:\nNonLagDotQQE ", TFToStr(iNLDTimeFrame2), ": ", buyOrSell(NLD2Direction), "\n");
   }

   if(bSuperTrendFilter)
   {
      strComment = StringConcatenate(strComment,"\nFilter:\nSuperTrend ", TFToStr(iSTTimeFrame), ": ", buyOrSell(SuperTrendDirection), "\n");
   }

   if(bXO_A_H_Filter)
   {
      strComment = StringConcatenate(strComment,"\nFilter:\nXO_A_H Filter ", TFToStr(iXO_A_H_TimeFrame), ": ");
      
      string not_;
      not_ = "";
      if (!XO_A_H_CanBuy) not_ = " not";

      strComment = StringConcatenate(strComment, " Buys", not_, " allowed, ");
      
      not_ = "";
      if (!XO_A_H_CanSell) not_ = " not";

      strComment = StringConcatenate(strComment, " Sells", not_, " allowed.\n");
   }
   
   strComment = StringConcatenate(strComment,"\nprofit = ",DoubleToStr(buyorderprofit+sellorderprofit,2));

   Comment(strComment);

   if (
            (oppositeclose && sell && !buy)
         || (nonlagmaexit && (nlmya>350 && nlmy<350) || (nlmga>350 && nlmg<350) || (nlmra>350 && nlmr<350))
         || (NLDExitBuysSignal)
         || (NonLagDotCloseBuy)
         || (qqeExitBuy)// qqe close buy signal
         
         || (SlopeDirectionCloseBuySignal)
         || (XO_A_H_CloseBuy)
         || (THVTrix_CloseBuy)
         || (FX_Secret_CloseBuy)         
      ) 
   {
      closebuy();
   }
   
   if (
            (oppositeclose && buy && !sell)
         || (nonlagmaexit && (nlmya>350 && nlmy<350) || (nlmga>350 && nlmg<350) || (nlmra>350 && nlmr<350))
         || (NLDExitSellsSignal)
         || (NonLagDotCloseSell)
         || (qqeExitSell)// qqe close sell signal
         
         || (SlopeDirectionCloseSellSignal)
         || (XO_A_H_CloseSell)
         || (THVTrix_CloseSell)
         || (FX_Secret_CloseSell)
      )
   {
      closesell();
   }

   if(hidesl)hideclosebuy();
   if(hidetp)hideclosesell();

   if(generalfilter){
      nstarthour=starthour+(gmtshift);if(nstarthour>23)nstarthour=nstarthour-24;
      if(nstarthour<10)istarthour="0"+nstarthour;
      if(nstarthour>9)istarthour=nstarthour;
      if(startminutes<10)istartminutes="0"+startminutes;
      if(startminutes>9)istartminutes=startminutes;
      tstart=StrToTime(istarthour+":"+istartminutes);

      nendhour=endhour+(gmtshift);if(nendhour>23)nendhour=nendhour-24;
      if(nendhour<10)iendhour="0"+nendhour;
      if(nendhour>9)iendhour=nendhour;
      if(endminutes<10)iendminutes="0"+endminutes;
      if(endminutes>9)iendminutes=endminutes;
      tend=StrToTime(iendhour+":"+iendminutes);
      
   }
   
   if(generalfilter2){
      int nstarthour2=starthour2+(gmtshift);if(nstarthour2>23)nstarthour2=nstarthour2-24;
      if(nstarthour2<10)istarthour="0"+nstarthour2;
      if(nstarthour2>9)istarthour=nstarthour2;
      if(startminutes2<10)istartminutes="0"+startminutes2;
      if(startminutes2>9)istartminutes=startminutes2;
      datetime tstart2=StrToTime(istarthour+":"+istartminutes);      

      int nendhour2=endhour2+(gmtshift);if(nendhour2>23)nendhour2=nendhour2-24;
      if(nendhour2<10)iendhour="0"+nendhour2;
      if(nendhour2>9)iendhour=nendhour2;
      if(endminutes2<10)iendminutes="0"+endminutes2;
      if(endminutes2>9)iendminutes=endminutes2;
      datetime tend2=StrToTime(iendhour+":"+iendminutes);
   }
   
   if(generalfilter3){
      int nstarthour3=starthour3+(gmtshift);if(nstarthour3>23)nstarthour3=nstarthour3-24;
      if(nstarthour3<10)istarthour="0"+nstarthour3;
      if(nstarthour3>9)istarthour=nstarthour3;
      if(startminutes3<10)istartminutes="0"+startminutes3;
      if(startminutes3>9)istartminutes=startminutes3;
      datetime tstart3=StrToTime(istarthour+":"+istartminutes);

      int nendhour3=endhour3+(gmtshift);if(nendhour3>23)nendhour3=nendhour3-24;
      if(nendhour3<10)iendhour="0"+nendhour3;
      if(nendhour3>9)iendhour=nendhour3;
      if(endminutes3<10)iendminutes="0"+endminutes3;
      if(endminutes3>9)iendminutes=endminutes3;
      datetime tend3=StrToTime(iendhour+":"+iendminutes);
   }
   
   if(fridayfilter){
      nfridayhour=fridayhour+(gmtshift);if(nfridayhour>23)nfridayhour=nfridayhour-24;
      if(nfridayhour<10)ifridayhour="0"+nfridayhour;
      if(nfridayhour>9)ifridayhour=nfridayhour;
      if(fridayminutes<10)ifridayminutes="0"+fridayminutes;
      if(fridayminutes>9)ifridayminutes=fridayminutes;
      tfriday=StrToTime(ifridayhour+":"+ifridayminutes);
   }
   
   if((tradesunday==false && DayOfWeek()==0) || (fridayfilter && DayOfWeek()==5 && TimeCurrent()>tfriday))return(0);
   
   if( !generalfilter || (nstarthour<=nendhour && (TimeCurrent()<tstart || TimeCurrent()>tend)) || (nstarthour>nendhour && TimeCurrent()<tstart && TimeCurrent()>tend))
   {
       if(!generalfilter2 || (nstarthour2<=nendhour2 && (TimeCurrent()<tstart2 || TimeCurrent()>tend2)) || (nstarthour2>nendhour2 && TimeCurrent()<tstart2 && TimeCurrent()>tend2))
       {           
           if(!generalfilter3 || (nstarthour3<=nendhour3 && (TimeCurrent()<tstart3 || TimeCurrent()>tend3)) || (nstarthour3>nendhour3 && TimeCurrent()<tstart3 && TimeCurrent()>tend3))
           {
               if (generalfilter || generalfilter2 || generalfilter3)
               {
                   return(0);      
               }
           }
       }
   }

   if((ask-bid)>maxspread*mt*pt)return(0);
   if((count(OP_BUY)+count(OP_SELL))>=maxtrades)return(0);

   if(mm /*&& (martingale==false || (martingale && lastprofit>=0))*/)lots=lotsoptimized();

   int expire=0;
   if(expiration>0)expire=TimeCurrent()+(expiration*60)-5;
   
   if( buy && tpb<tradesperbar  ){
      /*if(martingale)ilots=mlots;else*/ ilots=lots;
      if(ecn==false){
         ticket=open(OP_BUY,ilots,lotincsize,ask,stoploss,takeprofit,expire,Blue);
      }
      if(ecn){
         ticket=open(OP_BUY,ilots,lotincsize,ask,0,0,expire,Blue);
         createlstoploss(stoploss);
         createltakeprofit(takeprofit);
      }
      if(ticket<=0){/*Print("Error Occured : "+errordescription(GetLastError()));*/}
      else
      {
          tpb++;
          iEnabledNLDTrend = -1;
      }
   }
 
   if(
      sell && tps<tradesperbar        
   ){
      
      
      /*if(martingale)ilots=mlots;else*/ ilots=lots;
      if(ecn==false){
         //Print("iOpenOrders = "+iOpenOrders+" | lotincsize = "+lotincsize);
         ticket=open(OP_SELL,ilots,lotincsize,bid,stoploss,takeprofit,expire,Red);
      }
      if(ecn){
         //Print("iOpenOrders = "+iOpenOrders+" | lotincsize = "+lotincsize);
         ticket=open(OP_SELL,ilots,lotincsize,bid,0,0,expire,Red);
         createsstoploss(stoploss);
         createstakeprofit(takeprofit);
      }
      if(ticket<=0){/*Print("Error Occured : "+errordescription(GetLastError()));*/}
      else
      {
          tps++;
          iEnabledNLDTrend = -1;
      }
   }
   return(0);
}

bool Fits(double value)
{
   return (value != 0 && value != EMPTY_VALUE);
}

//|---------open

int open(int type,double lots,double lots_increase,double price,int stoploss,int takeprofit,int expire,color clr)
{
   int i=0;
   int tries=100;
   int error=0;
   int ticket=0;
   lots=NormalizeDouble(lots,lotdigits);
   if(lotdigits == 2) minlot=0.01;
   if(lots < minlot) lots=minlot;
   if(lots > maxlot) lots=maxlot;
   if(type==OP_BUY || type==OP_BUYSTOP || type==OP_BUYLIMIT)
   {
      if(hidesl==false && stoploss>0){sl=price-stoploss*pt;}else{sl=0;}
      if(hidetp==false && takeprofit>0){tp=price+takeprofit*pt;}else{tp=0;}
   }
   if(type==OP_SELL || type==OP_SELLSTOP || type==OP_SELLLIMIT)
   {
      if(hidesl==false && stoploss>0){sl=price+stoploss*pt;}else{sl=0;}
      if(hidetp==false && takeprofit>0){tp=price-takeprofit*pt;}else{tp=0;}
   }
   for(i = 0;i < tries;i++)
   {
      ticket=OrderSend(Symbol(),type,lots + lots_increase,price,slippage * mt,sl,tp,comment + ". Magic: " + DoubleToStr(magic,0),magic,expire,clr);
      error=GetLastError();
      if(error==0/* NO_ERROR */)break;
      if(!(error==4/* SERVER_BUSY */ || error==137/* BROKER_BUSY */ || error==146/* TRADE_CONTEXT_BUSY */ || error==136/* OFF_QUOTES */))break;
      Sleep(1000);
   }
   return(ticket);
}

//|---------lots optimized

double lotsoptimized(){
   double lot;
   if(mm==true)lot=NormalizeDouble(AccountFreeMargin()/(100.0*(NormalizeDouble(MarketInfo(Symbol(),MODE_MARGINREQUIRED),4)+5.0)/risk)-0.05,lotdigits);
   else lot=lots;
   return(lot);
}

//|---------counter

int count(int type){
   cnt=0;
   if(OrdersTotal()>0){
      for(i=OrdersTotal();i>=0;i--){
         OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
         if(OrderSymbol()==Symbol() && OrderType()==type && OrderMagicNumber()==magic)cnt++;
      }
      return(cnt);
   }
}

//|---------close

void closebuy()
{
   int iOrders;
   if(OrdersTotal() > 0)
   {
      iOrders = 1;
      while(iOrders > 0)
      {
         iOrders = 0;
         for(i = 0;i < OrdersTotal();i++)
         {
            if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
            {
               if(OrderSymbol() == Symbol() && OrderMagicNumber() == magic && OrderType() == OP_BUY)
               {
                  iOrders++;
                  RefreshRates();
                  if(OrderClose(OrderTicket(),OrderLots(),Bid,slippage * mt,Blue))
                  {
                     i--;
                     iOrders--;
                  }
                  else
                  {
                     if(log_file) Alert("Could not close buy order. Error #",GetLastError());
                  }
               }
            }
            else
            {
               if(log_file) Alert("Could not select buy order. Error #",GetLastError());
            }
         }
      }
   }
}

void closesell()
{
   int iOrders;
   if(OrdersTotal() > 0)
   {
      iOrders = 1;
      while(iOrders > 0)
      {
         iOrders = 0;
         for(i = 0;i < OrdersTotal();i++)
         {
            if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
            {
               if(OrderSymbol() == Symbol() && OrderMagicNumber() == magic && OrderType() == OP_SELL)
               {
                  iOrders++;
                  RefreshRates();
                  if(OrderClose(OrderTicket(),OrderLots(),Ask,slippage * mt,Red))
                  {
                     i--;
                     iOrders--;
                  }
                  else
                  {
                     if(log_file) Alert("Could not close buy order. Error #",GetLastError());
                  }
               }
            }
            else
            {
               if(log_file) Alert("Could not select buy order. Error #",GetLastError());
            }
         }
      }
   }
}

void hideclosebuy(){
   if(OrdersTotal()>0){
      for(i=OrdersTotal();i>=0;i--){
         OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
         if(OrderSymbol()==Symbol() && OrderMagicNumber()==magic && OrderType()==OP_BUY
         && (takeprofit>0 && OrderProfit()>takeprofit*OrderLots()*10) || (stoploss>0 && OrderProfit()<(-1)*stoploss*OrderLots()*10-MarketInfo(Symbol(),MODE_SPREAD)*OrderLots()*10/mt)){
            OrderClose(OrderTicket(),OrderLots(),bid,slippage*mt);
         }
      }
   }
}

void hideclosesell(){
   if(OrdersTotal()>0){
      for(i=OrdersTotal();i>=0;i--){
         OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
         if(OrderSymbol()==Symbol() && OrderMagicNumber()==magic && OrderType()==OP_SELL
         && (takeprofit>0 && OrderProfit()>takeprofit*OrderLots()*10) || (stoploss>0 && OrderProfit()<(-1)*stoploss*OrderLots()*10-MarketInfo(Symbol(),MODE_SPREAD)*OrderLots()*10/mt)){
            OrderClose(OrderTicket(),OrderLots(),ask,slippage*mt);
         }
      }
   }
}

//|---------breakeven

void movebreakeven(int breakevengain,int breakeven){
   RefreshRates();
   ask=MarketInfo(Symbol(),MODE_ASK);
   bid=MarketInfo(Symbol(),MODE_BID);
   if(OrdersTotal()>0){
      for(i=OrdersTotal();i>=0;i--){
         OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
         if(OrderType()<=OP_SELL && OrderSymbol()==Symbol() && OrderMagicNumber()==magic){
            if(OrderType()==OP_BUY){
               if(NormalizeDouble((bid-OrderOpenPrice()),dg)>=NormalizeDouble(breakevengain*pt,dg)){
                  if((NormalizeDouble((OrderStopLoss()-OrderOpenPrice()),dg)<NormalizeDouble(breakeven*pt,dg)) || OrderStopLoss()==0){
                     OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(OrderOpenPrice()+breakeven*pt,dg),OrderTakeProfit(),0,Blue);
                     return(0);
                  }
               }
            }
            else{
               if(NormalizeDouble((OrderOpenPrice()-ask),dg)>=NormalizeDouble(breakevengain*pt,dg)){
                  if((NormalizeDouble((OrderOpenPrice()-OrderStopLoss()),dg)<NormalizeDouble(breakeven*pt,dg)) || OrderStopLoss()==0){
                     OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(OrderOpenPrice()-breakeven*pt,dg),OrderTakeProfit(),0,Red);
                     return(0);
                  }
               }
            }
         }
      }
   }
}

//|---------trailingstop

void movetrailingstop(double trailingstart,double trailingstop){
   RefreshRates();
   ask=MarketInfo(Symbol(),MODE_ASK);
   bid=MarketInfo(Symbol(),MODE_BID);
   if(OrdersTotal()>0){
      for(i=OrdersTotal();i>=0;i--){
         OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
         if(OrderType()<=OP_SELL && OrderSymbol()==Symbol() && OrderMagicNumber()==magic){
            if(OrderType()==OP_BUY){
               if(NormalizeDouble(ask,dg)>NormalizeDouble(OrderOpenPrice()+trailingstart*pt,dg)
               && NormalizeDouble(OrderStopLoss(),dg)<NormalizeDouble(bid-(trailingstop+trailingstep)*pt,dg)){
                  OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(bid-trailingstop*pt,dg),OrderTakeProfit(),0,Blue);
                  return(0);
               }
            }
            else{
               if(NormalizeDouble(bid,dg)<NormalizeDouble(OrderOpenPrice()-trailingstart*pt,dg)
               && (NormalizeDouble(OrderStopLoss(),dg)>(NormalizeDouble(ask+(trailingstop+trailingstep)*pt,dg))) || (OrderStopLoss()==0)){                 
                  OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(ask+trailingstop*pt,dg),OrderTakeProfit(),0,Red);
                  return(0);
               }
            }
         }
      }
   }
}

//|---------trailingprofit

void movetrailingprofit(double trailingstart,double trailingprofit){
   RefreshRates();
   ask=MarketInfo(Symbol(),MODE_ASK);
   bid=MarketInfo(Symbol(),MODE_BID);
   for(int i=0;i<OrdersTotal();i++){
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)){
         if(OrderSymbol()==Symbol()&& OrderMagicNumber()==magic){
            if(OrderType()==OP_BUY){
               if(NormalizeDouble(bid-OrderOpenPrice(),dg)<=NormalizeDouble((-1)*trailingstart*pt,dg)){
                  if(NormalizeDouble(OrderTakeProfit(),dg)>NormalizeDouble(bid+(trailingprofit+trailingstep)*pt,dg) || NormalizeDouble(OrderTakeProfit(),dg)==0){
                     OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),NormalizeDouble(bid+trailingprofit*pt,dg),0,Blue);
                  }
               }
            }
            if(OrderType()==OP_SELL){
               if(NormalizeDouble(OrderOpenPrice()-ask,dg)<=NormalizeDouble((-1)*trailingstart*pt,dg)){
                  if(NormalizeDouble(OrderTakeProfit(),dg)<NormalizeDouble(ask-(trailingprofit+trailingstep)*pt,dg)){
                     OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),NormalizeDouble(ask-trailingprofit*pt,dg),0,Red);
                  }
               }
            }
         }
      }
   }
}

void createlstoploss(int stoploss){
   RefreshRates();
   ask=MarketInfo(Symbol(),MODE_ASK);
   bid=MarketInfo(Symbol(),MODE_BID);
   for(int i=0;i<OrdersTotal();i++){
      OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
      if(OrderType()<=OP_SELL && OrderSymbol()==Symbol() && OrderMagicNumber()==magic){
         if(OrderType()==OP_BUY){
            if(OrderStopLoss()==0){                 
               OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(ask-stoploss*pt,dg),OrderTakeProfit(),0,Red);
               return(0);
            }
         }
      }
   }
}

void createsstoploss(int stoploss){
   RefreshRates();
   ask=MarketInfo(Symbol(),MODE_ASK);
   bid=MarketInfo(Symbol(),MODE_BID);
   for(int i=0;i<OrdersTotal();i++){
      OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
      if(OrderType()<=OP_SELL && OrderSymbol()==Symbol() && OrderMagicNumber()==magic){
         if(OrderType()==OP_SELL){
            if(OrderStopLoss()==0){                 
               OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(bid+stoploss*pt,dg),OrderTakeProfit(),0,Red);
               return(0);
            }
         }
      }
   }
}

void createltakeprofit(int takeprofit){
   RefreshRates();
   ask=MarketInfo(Symbol(),MODE_ASK);
   bid=MarketInfo(Symbol(),MODE_BID);
   for(int i=0;i<OrdersTotal();i++){
      OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
      if(OrderType()<=OP_SELL && OrderSymbol()==Symbol() && OrderMagicNumber()==magic){
         if(OrderType()==OP_BUY){
            if(OrderTakeProfit()==0){                 
               OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),NormalizeDouble(ask+takeprofit*pt,dg),0,Red);
               return(0);
            }
         }
      }
   }
}

void createstakeprofit(int takeprofit){
   RefreshRates();
   ask=MarketInfo(Symbol(),MODE_ASK);
   bid=MarketInfo(Symbol(),MODE_BID);
   int total=OrdersTotal();
   for(int i=0;i<OrdersTotal();i++){
      OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
      if(OrderType()<=OP_SELL && OrderSymbol()==Symbol() && OrderMagicNumber()==magic){
         if(OrderType()==OP_SELL){
            if(OrderTakeProfit()==0){                 
               OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),NormalizeDouble(bid-takeprofit*pt,dg),0,Red);
               return(0);
            }
         }
      }
   }
}

string buyOrSell(int iBuyOrSell)
{
   if(iBuyOrSell == OP_BUY)
   {
      return("buy");
   }
   else if(iBuyOrSell == OP_SELL)
   {
      return("sell");
   }
   return("No Signal");
}

string TFToStr(int tf)
{
   static string s;
   switch (tf)
   {
      case PERIOD_H1: s = "PERIOD_H1";
      case PERIOD_H4: s = "PERIOD_H4";
      case PERIOD_D1: s = "PERIOD_D1";
      case PERIOD_W1: s = "PERIOD_W1";
      case PERIOD_MN1:s = "PERIOD_MN1";
      default:        s = "PERIOD_M" + tf;
   }
   return (s);
}

int Signal(string sy="0",int tf=0)   {
   double up[3],dn[3];
   int _return=0;
   if(sy=="0")sy=Symbol();
   if(tf==0)tf=Period();
   up[0]=iCustom(sy,tf,"SDL_MAM",iSdlPeriod,iSdlMethod,iSdlPrice,0,1);
   up[1]=iCustom(sy,tf,"SDL_MAM",iSdlPeriod,iSdlMethod,iSdlPrice,0,2);
   up[2]=iCustom(sy,tf,"SDL_MAM",iSdlPeriod,iSdlMethod,iSdlPrice,0,3);
   dn[0]=iCustom(sy,tf,"SDL_MAM",iSdlPeriod,iSdlMethod,iSdlPrice,1,1);
   dn[1]=iCustom(sy,tf,"SDL_MAM",iSdlPeriod,iSdlMethod,iSdlPrice,1,2);
   dn[2]=iCustom(sy,tf,"SDL_MAM",iSdlPeriod,iSdlMethod,iSdlPrice,1,3);
  
   if(up[0]!=EMPTY_VALUE && up[1]!=EMPTY_VALUE && up[2]==EMPTY_VALUE) _return=1;
   if(dn[0]!=EMPTY_VALUE && dn[1]!=EMPTY_VALUE && dn[2]==EMPTY_VALUE ) _return=-1;
 return(_return);
}
int SignalSDL(string sy,int tf, int iSlopeDirectionPeriodPara, int iSlopeDirectionMethodPara, int iSlopeDirectionPricePara, int shift, bool exit=false)   {
   double up[3],dn[3];
   int _return=0;
   if(sy=="0")sy=Symbol();
   if(tf==0)tf=Period();
   up[0]=iCustom(sy,tf,"Slope Direction Line",iSlopeDirectionPeriodPara,iSlopeDirectionMethodPara,iSlopeDirectionPricePara,0,shift);
   up[1]=iCustom(sy,tf,"Slope Direction Line",iSlopeDirectionPeriodPara,iSlopeDirectionMethodPara,iSlopeDirectionPricePara,0,shift+1);
   up[2]=iCustom(sy,tf,"Slope Direction Line",iSlopeDirectionPeriodPara,iSlopeDirectionMethodPara,iSlopeDirectionPricePara,0,shift+2);
   dn[0]=iCustom(sy,tf,"Slope Direction Line",iSlopeDirectionPeriodPara,iSlopeDirectionMethodPara,iSlopeDirectionPricePara,1,shift);
   dn[1]=iCustom(sy,tf,"Slope Direction Line",iSlopeDirectionPeriodPara,iSlopeDirectionMethodPara,iSlopeDirectionPricePara,1,shift+1);
   dn[2]=iCustom(sy,tf,"Slope Direction Line",iSlopeDirectionPeriodPara,iSlopeDirectionMethodPara,iSlopeDirectionPricePara,1,shift+2);
  
  
   if(exit) {
      if(up[0]!=EMPTY_VALUE && up[1]!=EMPTY_VALUE && up[2]==EMPTY_VALUE) _return=1;
      if(dn[0]!=EMPTY_VALUE && dn[1]!=EMPTY_VALUE && dn[2]==EMPTY_VALUE ) _return=-1;
   }
  else   {
      if(bSlopeDirectionEntryAlways)   {
         if(up[0]!=EMPTY_VALUE && LastSDLTimeCheck != Time[0]) _return=1;
         if(dn[0]!=EMPTY_VALUE && LastSDLTimeCheck != Time[0]) _return=-1;
         
         LastSDLTimeCheck = Time[0];
         
      }
      else  {
         if(up[0]!=EMPTY_VALUE && up[1]!=EMPTY_VALUE && up[2]==EMPTY_VALUE) _return=1;
         if(dn[0]!=EMPTY_VALUE && dn[1]!=EMPTY_VALUE && dn[2]==EMPTY_VALUE ) _return=-1;
      }        
   }
 return(_return);
}

int SignalRSI()   
{
   int return_=0;
   double up[2];
   double dn[2];
//----   
   up[0]=iCustom(Symbol(),TF,"ARROW_RSI-8_CROSS-55 45alarton",0,"== RSI ===",RSIPeriod,0,10,500,0,1);
   up[1]=iCustom(Symbol(),TF,"ARROW_RSI-8_CROSS-55 45alarton",0,"== RSI ===",RSIPeriod,0,10,500,0,2);
   dn[0]=iCustom(Symbol(),TF,"ARROW_RSI-8_CROSS-55 45alarton",0,"== RSI ===",RSIPeriod,0,10,500,1,1);
   dn[1]=iCustom(Symbol(),TF,"ARROW_RSI-8_CROSS-55 45alarton",0,"== RSI ===",RSIPeriod,0,10,500,1,2);
   
   if(up[1]==EMPTY_VALUE && up[0]!=EMPTY_VALUE)return_=1;
   if(dn[1]==EMPTY_VALUE && dn[0]!=EMPTY_VALUE)return_=-1;
//----
   return(return_);  
}
int WPRSignal()
{
   double wpr;   

   wpr = iWPR(Symbol(), WPR_TimeFrame, WPR_Period, WPR_Shift);
   //wpr[1] = iWPR(Symbol(), WPR_TimeFrame, WPR_Period, WPR_Shift+1);
   
   if(wpr >= WPR_Top_Level && wpr <= 0) return(OP_SELL);
   else if(wpr >= -100 && wpr <= WPR_Bottom_level) return(OP_BUY);
   else return(-1);
}

int WPRSignal_1()
{
   double wpr;   

   wpr = iWPR(Symbol(), WPR_TimeFrame_1, WPR_Period_1, WPR_Shift_1);
   //wpr[1] = iWPR(Symbol(), WPR_TimeFrame, WPR_Period, WPR_Shift+1);
   
   if(wpr >= WPR_Top_Level_1 && wpr <= 0) return(OP_BUY);
   else if(wpr >= -100 && wpr <= WPR_Bottom_level_1) return(OP_SELL);
   else return(-1);
}

int QqeSignal(int tf, int sf, int rsi_period, int shift)   {
   double   qqe_main = iCustom(Symbol(), tf, "QQE", sf, rsi_period, 0, shift), 
            qqe_signal = iCustom(Symbol(), tf, "QQE", sf, rsi_period, 1, shift);
   
   if(qqe_main > qqe_signal ) return(OP_BUY);   
   else if(qqe_main < qqe_signal) return(OP_SELL);
   else return(-1);
}